<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button onclick="">发送</button>
  1111
  <ul id="container">
  </ul>
  <p id="removeTime"></p>
  <script>
    const electron = require('electron')
    const { ipcRenderer } = electron
    //  Window.init()
    var checkTime = function (i) {

      if (i < 10) {

        i = "0" + i;

      }

      return i;

    }
    var showtime = function () {

      var nowdate = new Date();

      var year = nowdate.getFullYear(),

        month = nowdate.getMonth() + 1,

        date = nowdate.getDate(),

        day = nowdate.getDay(),

        week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],

        h = nowdate.getHours(),

        m = nowdate.getMinutes(),

        s = nowdate.getSeconds(),

        h = checkTime(h),

        m = checkTime(m),

        s = checkTime(s);

      return year + "年" + month + "月" + date + "日" + week[day] + " " + h + ":" + m + ":" + s;

    }
    ipcRenderer.on('render', (event, val) => {
      console.log(val, 'index');
      let uls = document.querySelector('#container'), li = document.createElement('li')
      li.innerHTML = val + '<span id="del">删除</span><span id="remove">撤回</span>'
      uls.appendChild(li)
      let del = document.querySelector('#del'), removeEl = document.querySelector('#remove')
      del.addEventListener('click', (e) => {
        console.log(e);
        let currentLi = e.target.parentNode
        uls.removeChild(currentLi)
      })
      removeEl.addEventListener('click', (e) => {
        let currentLi = e.target.parentNode, removeTime = document.querySelector('#removeTime')
        uls.removeChild(currentLi)
        let data = showtime()
        removeTime.innerHTML = `撤回时间${data}`
        ipcRenderer.send('removeTime', `撤回时间${data}`)
        console.log(data);
      })
    })

  </script>
</body>

</html>
